package com.ruoyi.controller;

import com.ruoyi.MqttClientConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author Alan Zhang
 * @Date 2025/3/12 17:10
 */
public class SendController {
    @Autowired
    private MqttClientConfig client;

    @RequestMapping("/sendMessage")
    @ResponseBody
    public String sendMessage(int qos,boolean retained, String topic,String message){
        try {
            client.publish(qos, retained, topic, message);
            return "发送成功";
        } catch (Exception e) {
            e.printStackTrace();
            return "发送失败";
        }
    }
}
